<template>
  <div class="my" v-if="userInfo">
    <div class="top">
      <div class="top1">
        <div class="top-left">
          <div class="top-left-name">{{ userInfo.nickname }}</div>
          <div class="top-left-text">{{ userInfo.intro }}</div>
        </div>
        <!-- 因为新用户没有头像我们判断如果没有userInfo.avatar就用默认的,有要拼接基地址 -->
        <img
          v-if="userInfo.avatar"
          :src="baseUrl + userInfo.avatar"
          alt=""
          class="top-right"
          @click="goIntro"
        />
        <img
          v-else
          src="@/assets/logo.png"
          alt=""
          class="top-right"
          @click="goIntro"
        />
      </div>
      <ul class="top2">
        <li class="top-item">
          <div class="top-num">298</div>
          <div class="top-txt">累计名额</div>
        </li>
        <li class="top-item">
          <div class="top-num">298</div>
          <div class="top-txt">累计名额</div>
        </li>
        <li class="top-item">
          <div class="top-num">298</div>
          <div class="top-txt">累计名额</div>
        </li>
        <li class="top-item">
          <div class="top-num">298</div>
          <div class="top-txt">累计名额</div>
        </li>
      </ul>
      <div class="top3">
        <!-- 使用子组件 -->
        <!-- 父传子 -->
        <myCell
          @click="$router.push('/home/editinfo?type=position')"
          title="我的岗位"
          value="产品经理"
          icon="&#xe64d;"
        ></myCell>
      </div>
    </div>
    <div class="content">
      <div class="middle">
        <div class="middle-title">面经数据</div>
        <ul class="middle-data">
          <li class="middle-item">
            <div class="item1">昨日阅读<span>+300</span></div>
            <div class="item2">17</div>
            <div class="item3">阅读总数</div>
          </li>
          <li class="middle-item">
            <div class="item1">昨日阅读<span>+300</span></div>
            <div class="item2">17</div>
            <div class="item3">阅读总数</div>
          </li>
          <li class="middle-item">
            <div class="item1">昨日阅读<span>+300</span></div>
            <div class="item2">17</div>
            <div class="item3">阅读总数</div>
          </li>
        </ul>
      </div>
      <div class="bottom">
        <myCell title="我的岗位" value="产品经理" icon="&#xe655;"></myCell>
        <myCell title="我的岗位" value="产品经理" icon="&#xe656;"></myCell>
        <myCell title="我的岗位" value="产品经理" icon="&#xe654;"></myCell>
        <myCell title="我的岗位" value="产品经理" icon="&#xe648;"></myCell>
        <myCell title="我的岗位" value="产品经理" icon="&#xe64f;"></myCell>
        <myCell title="我的岗位" value="产品经理" icon="&#xe649;"></myCell>
      </div>
    </div>
  </div>
</template>
<script>
import myCell from './my-cell'
// 渲染页面
// 1.导入mapstate
import { mapState } from 'vuex'
// 获取token
// import { getToken } from '@/utils/token.js'
// 导入接口
// import { auInfo } from '@/api/my.js'
export default {
  components: {
    myCell
  },
  computed: {
    //   在computed使用
    ...mapState(['userInfo', 'isLogin'])
  },
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL
    }
  },
  created () {
    //   简洁版
    //   如果没登录
    //      如果有token 调用接口
    //      没有token 跳转登录页
    // 啰嗦版
    // 解决刷新vuex数据消失问题,每次刷新发送请求,封装接口,如果只是点击菜单栏页面跳转就不需要重新获取,刷新的时候我们发送请求重新获取到数据
    // 如果islogin是false发送请求获取数据
    // 在判断是否有token,没有跳回首页
    // token过期
    // if (!this.isLogin) {
    // 在有token的情况下才能获取接口,没有跳回到登录页
    // 还要考虑token过期.响应拦截器器处理
    //   if (getToken()) {
    //     auInfo()
    //       .then(res => {
    //         this.$store.commit('setUserInfo', res.data.data)
    //         this.$store.commit('setIsLogin', true)
    //         console.log(res)
    //       })
    //       .catch(err => {
    //         console.log(err)
    //       })
    //   } else {
    //     this.$router.push('/login')
    //   }
    // }
  },
  mounted () {
    //   解决背景色问题进入页面时改变body的背景色
    document.body.style.backgroundColor = '#f7f4f5'
  },
  beforeDestroy () {
    //   离开页面时还原body背景色
    document.body.style.backgroundColor = '#ffffff'
  },
  methods: {
    goIntro () {
      this.$router.push('/home/myInfo')
    }
  }
}
</script>
<style lang="less" scoped>
.my {
  //   height: 9000px;
  //   background-color: blue;
  .top {
    padding: 0 @p15;
    background: linear-gradient(45deg, #ce0031, #b8002c);
    position: relative;
    .top1 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 31px 0 28px;
      .top-left {
        .top-left-name {
          font-size: 21px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          text-align: left;
          color: #ffffff;
          line-height: 30px;
          letter-spacing: 0px;
          padding-bottom: 6px;
        }
        .top-left-text {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          line-height: 16px;
          letter-spacing: 0px;
        }
      }
      .top-right {
        width: 50px;
        height: 50px;
        border: 3px solid rgba(255, 255, 255, 0.38);
        border-radius: 50%;
      }
    }
    .top2 {
      display: flex;
      justify-content: space-between;

      .top-item {
        text-align: center;
        .top-num {
          font-size: 21px;
          font-family: DINAlternate, DINAlternate-Bold;
          font-weight: 700;
          text-align: center;
          color: #ffffff;
          line-height: 24px;
          letter-spacing: 0px;
          padding-bottom: 6px;
        }
        .top-txt {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: center;
          color: #ffffff;
          line-height: 16px;
          letter-spacing: 0px;
          padding: 6px 0 55px;
        }
      }
    }
    .top3 {
      position: absolute;
      bottom: -17px;
      left: 0;
      width: 100%;
      height: 55px;
      padding: 0 @p15;
    }
  }
  .content {
    background-color: #f7f4f5;
    padding: 23px @p15 0;
    .middle {
      padding: 19px @p15 16px;
      background-color: #fff;
      .middle-title {
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        text-align: left;
        color: #181a39;
        line-height: 20px;
        letter-spacing: 0px;
        padding-bottom: 16px;
      }
      .middle-data {
        display: flex;
        justify-content: space-between;
        .middle-item {
          text-align: center;
          font-size: 12px;
          .item1 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #b4b4bd;
            line-height: 14px;
            letter-spacing: 0px;
            span {
              color: #3fc9de;
            }
          }
          .item2 {
            font-size: 21px;
            font-family: DINAlternate, DINAlternate-Bold;
            font-weight: 700;
            text-align: center;
            color: #181a39;
            line-height: 24px;
            letter-spacing: 0px;
            padding: 10px 0;
          }
          .item3 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #545671;
            line-height: 16px;
            letter-spacing: 0px;
          }
        }
      }
    }
    .bottom {
      padding: 10px 0 20px;
      // background-color: brown;
    }
  }
}
</style>
